package com.schooldate.model.action;

import com.alibaba.fastjson.JSON;
import com.schooldate.base.BaseAction;
import com.schooldate.model.entity.UserFlower;
import com.schooldate.model.entity.UserInfo;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

/**
 * Created by etund on 2015/3/18 0018.
 */
@Controller
@Scope("prototype")
@SuppressWarnings("all")
public class UserFlowerAction extends BaseAction<UserFlower> {


    private String sendUserId;
    private String reciUserId;
    private Integer sendNum = 1;

    /**
     * 送花
     * @return
     * @throws Exception
     */
    public void sendFlower() throws Exception{
        UserInfo reciUser = this.userInfoService.getById(Long.parseLong(reciUserId));
        UserInfo sendUser = this.userInfoService.getById(Long.parseLong(sendUserId));
        if (sendUser.getFlowerSendLeft() >= sendNum){
            sendUser.setFlowerSendLeft(sendUser.getFlowerSendLeft() - sendNum);
            reciUser.setReciFlower(reciUser.getReciFlower() + sendNum);
            object.put("code",1);
            result = JSON.toJSONString(object);
            renderJson(result);
        }else{
            object.put("code",0);
            renderJson(result);
        }
    }

    public String getSendUserId() {
        return sendUserId;
    }

    public void setSendUserId(String sendUserId) {
        this.sendUserId = sendUserId;
    }

    public String getReciUserId() {
        return reciUserId;
    }

    public void setReciUserId(String reciUserId) {
        this.reciUserId = reciUserId;
    }

    public Integer getSendNum() {
        return sendNum;
    }

    public void setSendNum(Integer sendNum) {
        this.sendNum = sendNum;
    }
}
